const express=require('express')
const pool=require('../pool')
const r=express.Router()
r.get('/lg',(req,res,next)=>{
	let sql='select id from user_list where phone=? and pwd=?'
	let pwd=req.query.pwd
	let phone=req.query.phone
	pool.query(sql,[phone,pwd],(err,result)=>{
		if(err){
			next(err)
			return
		}
		if(result.length>0){
			res.send('ok')
		}else{
			res.send('err')
		}
	})
})
r.post('/login',(req,res,next)=>{
	let sql='insert into user_list(phone,pwd) value(?,?)'
	let phone=req.body.phone
	let pwd=req.body.pwd
	if(!/^1[3-9]\d{9}$/.test(phone)){
		res.send('phone-err')
		return
	}
	if(!pwd || pwd.length>12 || pwd.length<5){
		res.send('pwd-err')
		return
	}
	pool.query(sql,[phone,pwd],(err,result)=>{
		if(err){
			next(err)
			return
		}
		res.send('ok')
		console.log(result)
	})
})
module.exports=r
